let app = new Vue({
    el: '#app',
    data() {
        return {
            user: {
                create_time: '',
                nickname: "123",
                roleId: null,
                status: 0,
                token: "",
                user_id: 1,
                user_uuid: null,
                username: ""
            }
        }
    },
    methods: {
        http(url, method, data) {
            return new Promise((resovle, reject) => {
                let token = ''
                if(sessionStorage.getItem("token")) {
                    token = sessionStorage.getItem("token")
                }
                $.ajax(url, {
                    method: method,
                    contentType: "application/json;charset=utf-8",
                    data: JSON.stringify(data),
                    headers:{
                        Authorization:`Bearer ${token}`
                    },
                    success: function (data) {
                        resovle(data)
                    },
                    error: function (err) {
                        reject(err)
                    }
                })
            })
        },
        submit(e) {
            e.preventDefault();//阻止默认行为
            let url = 'http://127.0.0.1:3001';
            let self = this
            let username = $('#w3lName').val();
            let pwd = $('#w3lPwd').val();
            this.http(url + '/test/login', 'post', {
                username: username,
                pwd: pwd
            }).then(res => {
                sessionStorage.setItem('user',JSON.stringify(res.data.user))
                sessionStorage.setItem('token',res.data.token)
                self.$message.success('登录成功')
                window.location.reload = '/index.html'
            })
        }
    },
    mounted() {
        console.log('加载')
    }
}) 